﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Common;

namespace Common
{
    public static class RequiredRoleSupport
    {
        public static readonly DependencyProperty RequiredRoleProperty = DependencyProperty.RegisterAttached("RequiredRole", typeof(string), typeof(RequiredRoleSupport), new PropertyMetadata(ValidateRole));

        public static string GetRequiredRole(DependencyObject obj)
        {
            return (string)obj.GetValue(RequiredRoleProperty);
        }

        public static void SetRequiredRole(DependencyObject obj, string value)
        {
            obj.SetValue(RequiredRoleProperty, value);
        }

        public static void ValidateRole(object sender, DependencyPropertyChangedEventArgs e)
        {
            var control = sender as Control;
            var roleValue = (string)e.NewValue;

            //Logic
            if (roleValue == "Admin")
            {
                control.Visibility = Visibility.Visible;
            }
            else
            {
                control.Visibility = Visibility.Collapsed;
            }
        }
    }
}
